/*

Replication for Banda and Cluverius, "Elite Polarization, Party Extremity,
	and Affective Polarization."
	
See codebook file for more on the variables.

Note that we use Bischof's plottig graph scheme when creating our plots. If you have
	Stata 15, it should already be installed. If it isn't, then enter:
	
ssc install blindschemes, replace all
set scheme plottig

*/


* Replication for Figure 2

use "Figure 2 replication data.dta", clear
set scheme plottig

* correlations
corr housedem sendem if year>=1978
corr houserep senrep if year>=1978
corr housepol senpol if year>=1978

* Figure 1
graph twoway (line housedem year, lw(1)) ///
	(line houserep year, lc(black) lp(dash) lw(1)) if year>=1978, ///
	legend(pos(6) col(2) order(1 "Democrats" 2 "Republicans") size(medium)) ///
	ytitle("Elite conservatism", size(medium)) ylabel(-.5(.5)1, labsize(medium)) ///
	xtitle("") xlabel(1980(6)2016, labsize(medium)) ysize(4) xsize(4) ///
	title("House Party Ideology", size(medium)) yline(1, lc(white) lp(solid))
	
graph twoway (line sendem year, lw(1)) ///
	(line senrep year, lc(black) lp(dash) lw(1)) if year>=1978, ///
	legend(pos(6) col(2) order(1 "Democrats" 2 "Republicans") size(medium)) ///
	ytitle("Elite conservatism", size(medium)) ylabel(-.5(.5)1, labsize(medium)) ///
	xtitle("") xlabel(1980(6)2016, labsize(medium)) ysize(4) xsize(4) ///
	title("Senate Party Ideology", size(medium)) yline(1, lc(white) lp(solid))

graph twoway (line housepol year, lw(1)) ///
	(line senpol year, lc(black) lp(dash) lw(1)) if year>=1978, ///
	legend(pos(6) col(2) order(1 "House" 2 "Senate") size(medium)) ///
	ytitle("Elite polarization", size(medium)) ylabel(, labsize(medium)) ///
	xtitle("") xlabel(1980(6)2016, labsize(medium)) ysize(4) xsize(4) ///
	title("Elite Polarization by Chamber", size(medium))


	

* Replication for everything besides Figure 2 in the main paper

use "Main replication data.dta", clear
set scheme plottig


* Figure 1
histogram affppol2, discrete width(4) start(-97) percent ysize(4) xsize(4) ///
	ytitle("Percentage of observations", size(medium)) ylabel(0(5)20, labsize(medium)) ///
	xtitle(" " "Values", size(medium)) title("Affective polarization", size(medium)) ///
	xlabel(-100(25)100, labsize(medium)) yline(20, lc(white) lp(solid))

histogram demptherm, discrete width(4) start(-97) percent ysize(4) xsize(4) ///
	ytitle("Percentage of observations", size(medium)) ylabel(, labsize(medium)) ///
	xtitle(" " "Values", size(medium)) title("Democratic Party feeling thermometer", size(medium)) ///
	xlabel(0(20)100, labsize(medium))

histogram repptherm, discrete width(4) start(-97) percent ysize(4) xsize(4) ///
	ytitle("Percentage of observations", size(medium)) ylabel(, labsize(medium)) ///
	xtitle(" " "Values", size(medium)) title("Republican Party feeling thermometer", size(medium)) ///
	xlabel(0(20)100, labsize(medium))

	
* Table 1 summary stats
sum affppol2 demptherm repptherm housepol2 senpol2 housein2 houseout2 senin2 senout2 ///
	i.pid3 i.ideo3 sorting female i.race4 interest age c.educ2 c.income i.year i.prezyr if pid3!=2

	
* Table 2 and figure 3
reg affppol2 c.housepol2##c.interest i.pid3 i.ideo3 sorting female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight], cluster(year)
margins, dydx(housepol2) at(interest=(1 2 3)) predict(xb)
marginsplot, recast(scatter) yline(0, lc(red)) xtitle(" " "Level of interest in elections", size(medium)) ///
	ytitle("Marginal effects", size(medium)) ylabel(0(1)7, labsize(medium)) yline(7, lc(white) lp(solid)) ///
	title("Effects of House polarization" "on affective polarization", size(medium)) ///
	plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium))

reg affppol2 c.senpol2##c.interest i.pid3 i.ideo3 sorting female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight], cluster(year)
margins, dydx(senpol2) at(interest=(1 2 3)) predict(xb)
marginsplot, recast(scatter) yline(0, lc(red)) xtitle(" " "Level of interest in elections", size(medium)) ///
	ytitle("Marginal effects", size(medium)) ylabel(0(1)7, labsize(medium)) yline(7, lc(white) lp(solid)) ///
	title("Effects of Senate polarization" "on affective polarization", size(medium)) ///
	plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium))

	
* Table 3 and Figure 4
* Individual party therms
reg demptherm c.housepol2##i.pid3##c.interest i.ideo3 i.pid3##c.sorting female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight] if pid3!=2, cluster(year)
margins, dydx(housepol2) at(pid3=(1 3) interest=(1 2 3)) predict(xb) post
test _b[1bn._at] = _b[4._at]
display abs(_b[1bn._at] - _b[4._at])
test _b[2._at] = _b[5._at]
display abs(_b[2._at] - _b[5._at])
test _b[3._at] = _b[6._at]
display abs(_b[3._at] - _b[6._at])
marginsplot, recast(scatter) yline(0, lc(red)) xtitle("") ///
	ytitle("Marginal effects", size(medium)) ylabel(-10(2)0, labsize(medium)) yline(-10, lc(white) lp(solid)) ///
	title("", size(medium)) plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium)) ///
	xtitle(" " "Level of interest in elections", size(medium)) subtitle(, size(medium)) ///
	by(pid3) byopt(title("Effects of House polarization" "on Democratic thermometer", size(medium)))

reg repptherm c.housepol2##i.pid3##c.interest i.ideo3 i.pid3##c.sorting female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight] if pid3!=2, cluster(year)
margins, dydx(housepol2) at(pid3=(1 3) interest=(1 2 3)) predict(xb) post
test _b[1bn._at] = _b[4._at]
display abs(_b[1bn._at] - _b[4._at])
test _b[2._at] = _b[5._at]
display abs(_b[2._at] - _b[5._at])
test _b[3._at] = _b[6._at]
display abs(_b[3._at] - _b[6._at])
marginsplot, recast(scatter) yline(0, lc(red)) xtitle("") ///
	ytitle("Marginal effects", size(medium)) ylabel(-10(2)0, labsize(medium)) yline(-10, lc(white) lp(solid)) ///
	title("", size(medium)) plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium)) ///
	xtitle(" " "Level of interest in elections", size(medium)) subtitle(, size(medium)) ///
	by(pid3) byopt(title("Effects of House polarization" "on Republican thermometer", size(medium)))	
	
reg demptherm c.senpol2##i.pid3##c.interest i.ideo3 i.pid3##c.sorting female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight] if pid3!=2, cluster(year)
margins, dydx(senpol2) at(pid3=(1 3) interest=(1 2 3)) predict(xb) post
test _b[1bn._at] = _b[4._at]
display abs(_b[1bn._at] - _b[4._at])
test _b[2._at] = _b[5._at]
display abs(_b[2._at] - _b[5._at])
test _b[3._at] = _b[6._at]
display abs(_b[3._at] - _b[6._at])
marginsplot, recast(scatter) yline(0, lc(red)) xtitle("") ///
	ytitle("Marginal effects", size(medium)) ylabel(-10(2)0, labsize(medium)) yline(-10, lc(white) lp(solid)) ///
	title("", size(medium)) plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium)) ///
	xtitle(" " "Level of interest in elections", size(medium)) subtitle(, size(medium)) ///
	by(pid3) byopt(title("Effects of Senate polarization" "on Democratic thermometer", size(medium)))
	
reg repptherm c.senpol2##i.pid3##c.interest i.ideo3 i.pid3##c.sorting female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight] if pid3!=2, cluster(year)
margins, dydx(senpol2) at(pid3=(1 3) interest=(1 2 3)) predict(xb) post
test _b[1bn._at] = _b[4._at]
display abs(_b[1bn._at] - _b[4._at])
test _b[2._at] = _b[5._at]
display abs(_b[2._at] - _b[5._at])
test _b[3._at] = _b[6._at]
display abs(_b[3._at] - _b[6._at])
marginsplot, recast(scatter) yline(0, lc(red)) xtitle("") ///
	ytitle("Marginal effects", size(medium)) ylabel(-10(2)0, labsize(medium)) yline(-10, lc(white) lp(solid)) ///
	title("", size(medium)) plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium)) ///
	xtitle(" " "Level of interest in elections", size(medium)) subtitle(, size(medium)) ///
	by(pid3) byopt(title("Effects of Senate polarization" "on Republican thermometer", size(medium)))

	
* Table 4 and Figure 5
reg affppol2 c.housein2##c.interest c.houseout2##c.interest i.ideo3 sorting i.pid3 female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight], cluster(year)
margins, dydx(housein2) at(interest=(1 2 3)) predict(xb)
marginsplot, recast(scatter) yline(0, lc(red)) xtitle(" " "Level of interest in elections", size(medium)) ///
	ytitle("Marginal effects", size(medium)) ylabel(-1(1)7, labsize(medium)) yline(-1 7, lc(white) lp(solid)) ///
	title("Effects of in-party House" "extremity on affective polarization", size(medium)) ///
	plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium))
margins, dydx(houseout2) at(interest=(1 2 3)) predict(xb)
marginsplot, recast(scatter) yline(0, lc(red)) xtitle(" " "Level of interest in elections", size(medium)) ///
	ytitle("Marginal effects", size(medium)) ylabel(-1(1)7, labsize(medium)) yline(-1 7, lc(white) lp(solid)) ///
	title("Effects of opposition party House" "extremity on affective polarization", size(medium)) ///
	plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium))
margins, dydx(housein2 houseout2) at(interest=(1 2 3)) predict(xb) post //coeflegend
* Second and third differ significantly
test _b[housein2:1bn._at] = _b[houseout2:1bn._at]
display abs(_b[housein2:1bn._at] - _b[houseout2:1bn._at])
test _b[housein2:2._at] = _b[houseout2:2._at]
display abs(_b[housein2:2._at] - _b[houseout2:2._at])
test _b[housein2:3._at] = _b[houseout2:3._at]
display abs(_b[housein2:3._at] - _b[houseout2:3._at])
	
reg affppol2 c.senin2##c.interest c.senout2##c.interest i.ideo3 sorting i.pid3 female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight], cluster(year)
margins, dydx(senin2) at(interest=(1 2 3)) predict(xb)
marginsplot, recast(scatter) yline(0, lc(red)) xtitle(" " "Level of interest in elections", size(medium)) ///
	ytitle("Marginal effects", size(medium)) ylabel(-1(1)7, labsize(medium)) yline(-1 7, lc(white) lp(solid)) ///
	title("Effects of in-party Senate" "extremity on affective polarization", size(medium)) ///
	plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium))
margins, dydx(senout2) at(interest=(1 2 3)) predict(xb)
marginsplot, recast(scatter) yline(0, lc(red)) xtitle(" " "Level of interest in elections", size(medium)) ///
	ytitle("Marginal effects", size(medium)) ylabel(-1(1)7, labsize(medium)) yline(-1 7, lc(white) lp(solid)) ///
	title("Effects of opposition party Senate" "extremity on affective polarization", size(medium)) ///
	plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium))

margins, dydx(senin2 senout2) at(interest=(1 2 3)) predict(xb) post //coeflegend
* All are significantly differerent
test _b[senin2:1bn._at] = _b[senout2:1bn._at]
display abs(_b[senin2:1bn._at] - _b[senout2:1bn._at])
test _b[senin2:2._at] = _b[senout2:2._at]
display abs(_b[senin2:2._at] - _b[senout2:2._at])
test _b[senin2:3._at] = _b[senout2:3._at]
display abs(_b[senin2:3._at] - _b[senout2:3._at])




************
* Appendix *	
************

* Lagged measures

* Table 1 and Figure 1
reg affppol2 c.housepol2l##c.interest i.pid3 i.ideo3 sorting female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight], cluster(year)
margins, dydx(housepol2l) at(interest=(1 2 3)) predict(xb)
marginsplot, recast(scatter) yline(0, lc(red)) xtitle(" " "Level of interest in elections", size(medium)) ///
	ytitle("Marginal effects", size(medium)) ylabel(0(1)7, labsize(medium)) yline(7, lc(white) lp(solid)) ///
	title("Effects of House polarization" "on affective polarization", size(medium)) ///
	plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium))

reg affppol2 c.senpol2l##c.interest i.pid3 i.ideo3 sorting female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight], cluster(year)
margins, dydx(senpol2l) at(interest=(1 2 3)) predict(xb)
marginsplot, recast(scatter) yline(0, lc(red)) xtitle(" " "Level of interest in elections", size(medium)) ///
	ytitle("Marginal effects", size(medium)) ylabel(0(1)7, labsize(medium)) yline(7, lc(white) lp(solid)) ///
	title("Effects of Senate polarization" "on affective polarization", size(medium)) ///
	plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium))


* Table 2 and Figure 2
reg demptherm c.housepol2l##i.pid3##c.interest i.ideo3 i.pid3##c.sorting female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight] if pid3!=2, cluster(year)
margins, dydx(housepol2l) at(pid3=(1 3) interest=(1 2 3)) predict(xb) post
test _b[1bn._at] = _b[4._at]
display abs(_b[1bn._at] - _b[4._at])
test _b[2._at] = _b[5._at]
display abs(_b[2._at] - _b[5._at])
test _b[3._at] = _b[6._at]
display abs(_b[3._at] - _b[6._at])
marginsplot, recast(scatter) yline(0, lc(red)) xtitle("") ///
	ytitle("Marginal effects", size(medium)) ylabel(-9(1)0, labsize(medium)) yline(-9, lc(white) lp(solid)) ///
	title("", size(medium)) plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium)) ///
	xtitle(" " "Level of interest in elections", size(medium)) subtitle(, size(medium)) ///
	by(pid3) byopt(title("Effects of House polarization" "on Democratic thermometer", size(medium)))

reg repptherm c.housepol2l##i.pid3##c.interest i.ideo3 i.pid3##c.sorting female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight] if pid3!=2, cluster(year)
margins, dydx(housepol2l) at(pid3=(1 3) interest=(1 2 3)) predict(xb) post
test _b[1bn._at] = _b[4._at]
display abs(_b[1bn._at] - _b[4._at])
test _b[2._at] = _b[5._at]
display abs(_b[2._at] - _b[5._at])
test _b[3._at] = _b[6._at]
display abs(_b[3._at] - _b[6._at])
marginsplot, recast(scatter) yline(0, lc(red)) xtitle("") ///
	ytitle("Marginal effects", size(medium)) ylabel(-9(1)0, labsize(medium)) yline(-9, lc(white) lp(solid)) ///
	title("", size(medium)) plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium)) ///
	xtitle(" " "Level of interest in elections", size(medium)) subtitle(, size(medium)) ///
	by(pid3) byopt(title("Effects of House polarization" "on Republican thermometer", size(medium)))	
	
reg demptherm c.senpol2l##i.pid3##c.interest i.ideo3 i.pid3##c.sorting female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight] if pid3!=2, cluster(year)
margins, dydx(senpol2l) at(pid3=(1 3) interest=(1 2 3)) predict(xb) post
test _b[1bn._at] = _b[4._at]
display abs(_b[1bn._at] - _b[4._at])
test _b[2._at] = _b[5._at]
display abs(_b[2._at] - _b[5._at])
test _b[3._at] = _b[6._at]
display abs(_b[3._at] - _b[6._at])
marginsplot, recast(scatter) yline(0, lc(red)) xtitle("") ///
	ytitle("Marginal effects", size(medium)) ylabel(-9(1)0, labsize(medium)) yline(-9, lc(white) lp(solid)) ///
	title("", size(medium)) plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium)) ///
	xtitle(" " "Level of interest in elections", size(medium)) subtitle(, size(medium)) ///
	by(pid3) byopt(title("Effects of Senate polarization" "on Democratic thermometer", size(medium)))
	
reg repptherm c.senpol2l##i.pid3##c.interest i.ideo3 i.pid3##c.sorting female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight] if pid3!=2, cluster(year)
margins, dydx(senpol2l) at(pid3=(1 3) interest=(1 2 3)) predict(xb) post
test _b[1bn._at] = _b[4._at]
display abs(_b[1bn._at] - _b[4._at])
test _b[2._at] = _b[5._at]
display abs(_b[2._at] - _b[5._at])
test _b[3._at] = _b[6._at]
display abs(_b[3._at] - _b[6._at])
marginsplot, recast(scatter) yline(0, lc(red)) xtitle("") ///
	ytitle("Marginal effects", size(medium)) ylabel(-9(1)0, labsize(medium)) yline(-9, lc(white) lp(solid)) ///
	title("", size(medium)) plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium)) ///
	xtitle(" " "Level of interest in elections", size(medium)) subtitle(, size(medium)) ///
	by(pid3) byopt(title("Effects of Senate polarization" "on Republican thermometer", size(medium)))
		

* Table 3 and Figure 3
reg affppol2 c.housein2l##c.interest c.houseout2l##c.interest i.ideo3 sorting i.pid3 female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight], cluster(year)
margins, dydx(housein2l) at(interest=(1 2 3)) predict(xb)
marginsplot, recast(scatter) yline(0, lc(red)) xtitle(" " "Level of interest in elections", size(medium)) ///
	ytitle("Marginal effects", size(medium)) ylabel(-1(1)7, labsize(medium)) yline(-1 7, lc(white) lp(solid)) ///
	title("Effects of in-party House" "extremity on affective polarization", size(medium)) ///
	plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium))
margins, dydx(houseout2l) at(interest=(1 2 3)) predict(xb)
marginsplot, recast(scatter) yline(0, lc(red)) xtitle(" " "Level of interest in elections", size(medium)) ///
	ytitle("Marginal effects", size(medium)) ylabel(-1(1)7, labsize(medium)) yline(-1 7, lc(white) lp(solid)) ///
	title("Effects of opposition party House" "extremity on affective polarization", size(medium)) ///
	plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium))
margins, dydx(housein2l houseout2l) at(interest=(1 2 3)) predict(xb) post //coeflegend
* Second and third differ significantly
test _b[housein2l:1bn._at] = _b[houseout2l:1bn._at]
display abs(_b[housein2l:1bn._at] - _b[houseout2l:1bn._at])
test _b[housein2l:2._at] = _b[houseout2l:2._at]
display abs(_b[housein2l:2._at] - _b[houseout2l:2._at])
test _b[housein2l:3._at] = _b[houseout2l:3._at]
display abs(_b[housein2l:3._at] - _b[houseout2l:3._at])
	
reg affppol2 c.senin2l##c.interest c.senout2l##c.interest i.ideo3 sorting i.pid3 female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight], cluster(year)
margins, dydx(senin2l) at(interest=(1 2 3)) predict(xb)
marginsplot, recast(scatter) yline(0, lc(red)) xtitle(" " "Level of interest in elections", size(medium)) ///
	ytitle("Marginal effects", size(medium)) ylabel(-1(1)7, labsize(medium)) yline(-1 7, lc(white) lp(solid)) ///
	title("Effects of in-party Senate" "extremity on affective polarization", size(medium)) ///
	plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium))
margins, dydx(senout2l) at(interest=(1 2 3)) predict(xb)
marginsplot, recast(scatter) yline(0, lc(red)) xtitle(" " "Level of interest in elections", size(medium)) ///
	ytitle("Marginal effects", size(medium)) ylabel(-1(1)7, labsize(medium)) yline(-1 7, lc(white) lp(solid)) ///
	title("Effects of opposition party Senate" "extremity on affective polarization", size(medium)) ///
	plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium))

margins, dydx(senin2l senout2l) at(interest=(1 2 3)) predict(xb) post //coeflegend
* All are significantly differerent
test _b[senin2l:1bn._at] = _b[senout2l:1bn._at]
display abs(_b[senin2l:1bn._at] - _b[senout2l:1bn._at])
test _b[senin2l:2._at] = _b[senout2l:2._at]
display abs(_b[senin2l:2._at] - _b[senout2l:2._at])
test _b[senin2l:3._at] = _b[senout2l:3._at]
display abs(_b[senin2l:3._at] - _b[senout2l:3._at])


* CF scores
* Note: no 1978 or 2016 CF data

* Table 4 and Figure 4
reg affppol2 c.housepolcf2##c.interest i.pid3 i.ideo3 sorting female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight], cluster(year)
margins, dydx(housepolcf2) at(interest=(1 2 3)) predict(xb)
marginsplot, recast(scatter) yline(0, lc(red)) xtitle(" " "Level of interest in elections", size(medium)) ///
	ytitle("Marginal effects", size(medium)) ylabel(0(1)7, labsize(medium)) yline(7, lc(white) lp(solid)) ///
	title("Effects of House polarization" "on affective polarization", size(medium)) ///
	plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium))

reg affppol2 c.senpolcf2##c.interest i.pid3 i.ideo3 sorting female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight], cluster(year)
margins, dydx(senpolcf2) at(interest=(1 2 3)) predict(xb)
marginsplot, recast(scatter) yline(0, lc(red)) xtitle(" " "Level of interest in elections", size(medium)) ///
	ytitle("Marginal effects", size(medium)) ylabel(0(1)7, labsize(medium)) yline(7, lc(white) lp(solid)) ///
	title("Effects of Senate polarization" "on affective polarization", size(medium)) ///
	plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium))


* Table 5 and Figure 5
reg demptherm c.housepolcf2##i.pid3##c.interest i.ideo3 i.pid3##c.sorting female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight] if pid3!=2, cluster(year)
margins, dydx(housepolcf2) at(pid3=(1 3) interest=(1 2 3)) predict(xb) post
* All differ from one another
test _b[1bn._at] = _b[4._at]
display abs(_b[1bn._at] - _b[4._at])
test _b[2._at] = _b[5._at]
display abs(_b[2._at] - _b[5._at])
test _b[3._at] = _b[6._at]
display abs(_b[3._at] - _b[6._at])
marginsplot, recast(scatter) yline(0, lc(red)) xtitle("") ///
	ytitle("Marginal effects", size(medium)) ylabel(-9(1)0, labsize(medium)) yline(-9, lc(white) lp(solid)) ///
	title("", size(medium)) plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium)) ///
	xtitle(" " "Level of interest in elections", size(medium)) subtitle(, size(medium)) ///
	by(pid3) byopt(title("Effects of House polarization" "on Democratic thermometer", size(medium)))

reg repptherm c.housepolcf2##i.pid3##c.interest i.ideo3 i.pid3##c.sorting female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight] if pid3!=2, cluster(year)
margins, dydx(housepolcf2) at(pid3=(1 3) interest=(1 2 3)) predict(xb) post
* All differ from one another
test _b[1bn._at] = _b[4._at]
display abs(_b[1bn._at] - _b[4._at])
test _b[2._at] = _b[5._at]
display abs(_b[2._at] - _b[5._at])
test _b[3._at] = _b[6._at]
display abs(_b[3._at] - _b[6._at])
marginsplot, recast(scatter) yline(0, lc(red)) xtitle("") ///
	ytitle("Marginal effects", size(medium)) ylabel(-9(1)0, labsize(medium)) yline(-9, lc(white) lp(solid)) ///
	title("", size(medium)) plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium)) ///
	xtitle(" " "Level of interest in elections", size(medium)) subtitle(, size(medium)) ///
	by(pid3) byopt(title("Effects of House polarization" "on Republican thermometer", size(medium)))

reg demptherm c.senpolcf2##i.pid3##c.interest i.ideo3 i.pid3##c.sorting female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight] if pid3!=2, cluster(year)
margins, dydx(senpolcf2) at(pid3=(1 3) interest=(1 2 3)) predict(xb) post
* All differ from one another
test _b[1bn._at] = _b[4._at]
display abs(_b[1bn._at] - _b[4._at])
test _b[2._at] = _b[5._at]
display abs(_b[2._at] - _b[5._at])
test _b[3._at] = _b[6._at]
display abs(_b[3._at] - _b[6._at])
marginsplot, recast(scatter) yline(0, lc(red)) xtitle("") ///
	ytitle("Marginal effects", size(medium)) ylabel(-9(1)0, labsize(medium)) yline(-9, lc(white) lp(solid)) ///
	title("", size(medium)) plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium)) ///
	xtitle(" " "Level of interest in elections", size(medium)) subtitle(, size(medium)) ///
	by(pid3) byopt(title("Effects of Senate polarization" "on Democratic thermometer", size(medium)))

reg repptherm c.senpolcf2##i.pid3##c.interest i.ideo3 i.pid3##c.sorting female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight] if pid3!=2, cluster(year)
margins, dydx(senpolcf2) at(pid3=(1 3) interest=(1 2 3)) predict(xb) post
test _b[1bn._at] = _b[4._at]
display abs(_b[1bn._at] - _b[4._at])
test _b[2._at] = _b[5._at]
display abs(_b[2._at] - _b[5._at])
test _b[3._at] = _b[6._at]
display abs(_b[3._at] - _b[6._at])
marginsplot, recast(scatter) yline(0, lc(red)) xtitle("") ///
	ytitle("Marginal effects", size(medium)) ylabel(-9(1)0, labsize(medium)) yline(-9, lc(white) lp(solid)) ///
	title("", size(medium)) plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium)) ///
	xtitle(" " "Level of interest in elections", size(medium)) subtitle(, size(medium)) ///
	by(pid3) byopt(title("Effects of Senate polarization" "on Republican thermometer", size(medium)))


* Table 6 and Figure 6
reg affppol2 c.houseincf2##c.interest c.houseoutcf2##c.interest i.ideo3 sorting i.pid3 female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight], cluster(year)
margins, dydx(houseincf2) at(interest=(1 2 3)) predict(xb)
marginsplot, recast(scatter) yline(0, lc(red)) xtitle(" " "Level of interest in elections", size(medium)) ///
	ytitle("Marginal effects", size(medium)) ylabel(-1(1)10, labsize(medium)) yline(-1 10, lc(white) lp(solid)) ///
	title("Effects of in-party House" "extremity on affective polarization", size(medium)) ///
	plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium))
margins, dydx(houseoutcf2) at(interest=(1 2 3)) predict(xb)
marginsplot, recast(scatter) yline(0, lc(red)) xtitle(" " "Level of interest in elections", size(medium)) ///
	ytitle("Marginal effects", size(medium)) ylabel(-1(1)10, labsize(medium)) yline(-1 10, lc(white) lp(solid)) ///
	title("Effects of opposition party House" "extremity on affective polarization", size(medium)) ///
	plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium))
margins, dydx(houseincf2 houseoutcf2) at(interest=(1 2 3)) predict(xb) post //coeflegend
* None differ
test _b[houseincf2:1bn._at] = _b[houseoutcf2:1bn._at]
display abs(_b[houseincf2:1bn._at] - _b[houseoutcf2:1bn._at])
test _b[houseincf2:2._at] = _b[houseoutcf2:2._at]
display abs(_b[houseincf2:2._at] - _b[houseoutcf2:2._at])
test _b[houseincf2:3._at] = _b[houseoutcf2:3._at]
display abs(_b[houseincf2:3._at] - _b[houseoutcf2:3._at])


reg affppol2 c.senincf2##c.interest c.senoutcf2##c.interest i.ideo3 sorting i.pid3 female i.race4 age ///
	c.educ2 c.income i.prezyr i.year [pweight=weight], cluster(year)
margins, dydx(senincf2) at(interest=(1 2 3)) predict(xb)
marginsplot, recast(scatter) yline(0, lc(red)) xtitle(" " "Level of interest in elections", size(medium)) ///
	ytitle("Marginal effects", size(medium)) ylabel(-1(1)10, labsize(medium)) yline(-1 10, lc(white) lp(solid)) ///
	title("Effects of in-party Senate" "extremity on affective polarization", size(medium)) ///
	plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium))
margins, dydx(senoutcf2) at(interest=(1 2 3)) predict(xb)
marginsplot, recast(scatter) yline(0, lc(red)) xtitle(" " "Level of interest in elections", size(medium)) ///
	ytitle("Marginal effects", size(medium)) ylabel(-1(1)10, labsize(medium)) yline(-1 10, lc(white) lp(solid)) ///
	title("Effects of opposition party Senate" "extremity on affective polarization", size(medium)) ///
	plot1opts(mc("black") msize(2.5)) ciopts(col(black) ls(2) lw(.9)) ///
	xscale(range(0.8 3.2)) xsize(4) ysize(4) xlabel(1 "Low" 2 "Middle" 3 "High", labsize(medium))
margins, dydx(senincf2 senoutcf2) at(interest=(1 2 3)) predict(xb) post //coeflegend
* All differ, but unexpected direction
test _b[senincf2:1bn._at] = _b[senoutcf2:1bn._at]
display abs(_b[senincf2:1bn._at] - _b[senoutcf2:1bn._at])
test _b[senincf2:2._at] = _b[senoutcf2:2._at]
display abs(_b[senincf2:2._at] - _b[senoutcf2:2._at])
test _b[senincf2:3._at] = _b[senoutcf2:3._at]
display abs(_b[senincf2:3._at] - _b[senoutcf2:3._at])
